package com.fileuptool.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.fileuptool.service.FileUpService;

import io.swagger.annotations.ApiOperation;


/**
 * 
 * @author dinghao
* @ClassName: FileUpController 
* @Description: TODO
* @date 2018年3月15日 下午4:40:27 
*
 */
@RestController
public class FileUpController {

	@Autowired
	private FileUpService fileUpService;
	
	@PostMapping(value = "/file")
	@ResponseBody
	@ApiOperation("Upload files.")
	public String uploadFile(@RequestParam("file") MultipartFile file) {
		boolean b = false;
		try {
			b = fileUpService.writeFile(file);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(b) {
			return "文件上传成功!";
		}
		return "文件上传失败!";
	}
}
